import mplfinance as mpf
import pandas as pd
import akshare as ak

print("starting mplfinance .....")
df = ak.stock_zh_a_hist(
    symbol="000001",
    period="daily",
    start_date="20230601",
    end_date="20231101",
    adjust="",
)
df = df.iloc[:, 0:6]
df.日期 = pd.to_datetime(df.日期)

# 列名记得这样定义好
df.columns = ["Date", "Open", "Close", "High", "Low", "Volume"]
df.set_index("Date", inplace=True)

# mpf.plot(df, type="candle", mav=(5, 10, 20), volume=True)

# 设置样式
market_colors = mpf.make_marketcolors(
    up="g",
    down="r",
    edge="lime",
    wick={"up": "blue", "down": "orange"},
    volume="gray",
    ohlc="black",
)

# marketcolors (必须) K线(高开低收)和量
# mavcolors (可选) 设置移动均线
# matplotlib_style (可选) see matplotli document

my_style = mpf.make_mpf_style(marketcolors=market_colors)

mpf.plot(df, mav=(5, 8, 13), volume=True, style=my_style)

print("end")
